package logic

import (
	"context"
	"fmt"
	"good_srv/good"
	"good_srv/internal/svc"
	"good_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActiveAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewActiveAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActiveAddLogic {
	return &ActiveAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 活动添加
func (l *ActiveAddLogic) ActiveAdd(in *good.ActiveAddRequest) (*good.ActiveAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	actives := models.Active{
		Name:      in.Name,
		Price:     float64(in.Price),
		Stock:     in.Stock,
		Process:   int(in.Process),
		Countdown: in.Countdown,
		Status:    int(in.Status),
	}
	if err = actives.ActiveAdd(); err != nil {
		logx.Error("活动创建失败")
		return nil, fmt.Errorf("活动创建失败")
	}
	return &good.ActiveAddResponse{
		Id: int64(actives.ID),
	}, nil
}
